package com.heu.blood.match.controller;


import com.heu.blood.common.aop.ControllerLogAnnotation;
import com.heu.blood.common.utils.PageUtils;
import com.heu.blood.common.utils.R;
import com.heu.blood.match.entity.PatientBloodTypeDataEntity;
import com.heu.blood.match.entity.PatientInformationEntity;
import com.heu.blood.match.service.PatientInformationService;
import com.heu.blood.match.vo.PatientBloodTypeQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 *
 *
 * @author lrz
 * @since 2023-07-05
 */
@RestController
@RequestMapping("/match/patient")
public class PatientInformationController {
    @Autowired
    private PatientInformationService patientInformationService;


    /**
     * 分页查询患者信息表数据
     * @param params
     * @return
     */
    @GetMapping("/list")
    @ControllerLogAnnotation(module = "病人信息", operate = "分页查询患者信息表数据")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page =  patientInformationService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 根据patientId获取patientInformation表信息
     * @param patientId
     * @return
     */
    @GetMapping("/{patientId}")
    @ControllerLogAnnotation(module = "病人信息", operate = "根据patientId获取patientInformation表信息")
    public R queryWithPatientId(@PathVariable String patientId){
        PatientInformationEntity patientInformationEntity = patientInformationService.queryWithPatientId(patientId);
        return R.ok().put("list", patientInformationEntity);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @ControllerLogAnnotation(module = "病人信息", operate = "条件查询patientInformation表信息")
    public R info(@PathVariable("id") Integer id){
        PatientInformationEntity patientInformation = patientInformationService.getById(id);

        return R.ok().put("data", patientInformation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @ControllerLogAnnotation(module = "病人信息", operate = "保存patientInformation表信息")
    public R save(@RequestBody PatientInformationEntity patientInformation){
        patientInformationService.save(patientInformation);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @ControllerLogAnnotation(module = "病人信息", operate = "修改patientInformation表信息")
    public R update(@RequestBody PatientInformationEntity patientInformation){
        patientInformationService.updateById(patientInformation);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @ControllerLogAnnotation(module = "病人信息", operate = "删除patientInformation表信息")
    public R delete(@RequestBody Integer[] ids){
        patientInformationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }


    @RequestMapping("patientBloodTypeQuery")
    @ControllerLogAnnotation(module = "病人信息", operate = "查询患者血型分布信息")
    public R patientBloodTypeQuery(@RequestBody PatientBloodTypeQueryVo patientBloodTypeQueryVo){
        List<PatientBloodTypeDataEntity> result=patientInformationService.patientBloodTypeQuery(patientBloodTypeQueryVo);

        return R.ok().put("data",result);
    }

}

